import Foundation

class userBasicInfoManager{
    
    private static let ASMX_NAME="BasicInfoManageInterface.asmx"

    //函数名:GetUserBasicInfoByUserId  1-根据用户Id获取用户基本信息接口
    //@param  userId  String  用户UserId
    //返回参数列表如下:
    //@param BasicInfoId  String  编号
    //@param UserId  String  用户id
    //@param UserName  String  姓名
    //@param Gender  String  性别
    //@param Marrige  String  婚姻状况
    //@param Birthday  String  出生日期
    //@param Degree  String  最高学历
    //@param YearOfWork  String  工作年限
    //@param Mobile  String  手机号码
    //@param Email  String  邮箱
    //@param Location  String  现居地城市编码
    //@param Photo  String  头像
    //@param CreateDate  String  创建时间
    //@param UpdateDate  String  更新时间
    //@param CityName  String  现居地城市名称
    static func GetUserBasicInfoByUserId(userId:String,
                             successCallback:(theRetList:[userBasicInfo])->Void,
                             failCallback:(error:String)->Void)
    {
            let mysoap=soapUtil()

            mysoap.setName(ASMX_NAME, methodName: "GetUserBasicInfoByUserId")

            mysoap.addParam("userId", value: userId)//用户UserId

            mysoap.send({ (data) in
            var retList=[userBasicInfo]()
                if let rows=data["rows"].array{
                    for singleRow in rows{
                        let single=userBasicInfo()
                        
                        single.BasicInfoId=singleRow["BasicInfoId"].string!  //编号
                        single.UserId=singleRow["UserId"].string!  //用户id
                        single.UserName=singleRow["UserName"].string!  //姓名
                        single.Gender=singleRow["Gender"].string!  //性别
                        single.Marrige=singleRow["Marrige"].string!  //婚姻状况
                        single.Birthday=singleRow["Birthday"].string!  //出生日期
                        single.Degree=singleRow["Degree"].string!  //最高学历
                        single.YearOfWork=singleRow["YearOfWork"].string!  //工作年限
                        single.Mobile=singleRow["Mobile"].string!  //手机号码
                        single.Email=singleRow["Email"].string!  //邮箱
                        single.Location=singleRow["Location"].string!  //现居地城市编码
                        single.Photo=singleRow["Photo"].string!  //头像
                        single.CreateDate=singleRow["CreateDate"].string!  //创建时间
                        single.UpdateDate=singleRow["UpdateDate"].string!  //更新时间
                        single.CityName=singleRow["CityName"].string!  //现居地城市名称

                        retList.append(single)
                    }
                    successCallback(theRetList:retList)
                }
        }) { (error) in
            failCallback(error: "获取失败")
        }
    }

    //函数名:UpdateUserBasicInfo  2-根据用户Id修改用户基本信息
    //@param  userId  String  用户UserId
    //@param  userName  String  姓名
    //@param  gender  Int  性别（1：男，2：女）
    //@param  marriage  Int  婚姻状况（1已婚，2未婚）
    //@param  birthday  NSDate  出生日期
    //@param  degree  Int  最高学历
    //@param  workyear  Int  工作年限
    //@param  mobile  String  手机号码
    //@param  email  String  电子邮箱
    //@param  location  Int  现居地
    //成功返回true或者false
    static func UpdateUserBasicInfo(userId:String,
                             userName:String,
                             gender:Int,
                             marriage:Int,
                             birthday:NSDate,
                             degree:Int,
                             workyear:Int,
                             mobile:String,
                             email:String,
                             location:Int,
                             successCallback:(msg:String)->Void,
                             failCallback:(error:String)->Void)
    {
            let mysoap=soapUtil()

            mysoap.setName(ASMX_NAME, methodName: "UpdateUserBasicInfo")

            mysoap.addParam("userId", value: userId)//用户UserId
            mysoap.addParam("userName", value: userName)//姓名
            mysoap.addParam("gender", value: String(gender))//性别（1：男，2：女）
            mysoap.addParam("marriage", value: String(marriage))//婚姻状况（1已婚，2未婚）
            let DateFormatter=NSDateFormatter()
            DateFormatter.dateFormat="yyyy-MM-ddTHH:mm:ss"
            let convertDate=DateFormatter.stringFromDate(birthday)
            mysoap.addParam("birthday", value: convertDate)//出生日期
            mysoap.addParam("degree", value: String(degree))//最高学历
            mysoap.addParam("workyear", value: String(workyear))//工作年限
            mysoap.addParam("mobile", value: mobile)//手机号码
            mysoap.addParam("email", value: email)//电子邮箱
            mysoap.addParam("location", value: String(location))//现居地

            mysoap.send({ (data) in
                if data["result"] != nil{
                    if(data["result"].string == "true"){
                        successCallback(msg: data["msg"].string!)
                    }else{
                        failCallback(error: data["msg"].string!)
                    }
                }else{
                    failCallback(error: "修改失败")
                }
        }) { (error) in
            failCallback(error: "修改失败")
        }
    }

    //函数名:UploadLogo  3-上传头像图片接口(有问题不用做)
    //@param  userId  String  用户UserId
    //@param  path  String  头像图片的路径
    //成功返回true或者false
    static func UploadLogo(userId:String,
                             path:String,
                             successCallback:(msg:String)->Void,
                             failCallback:(error:String)->Void)
    {
            let mysoap=soapUtil()

            mysoap.setName(ASMX_NAME, methodName: "UploadLogo")

            mysoap.addParam("userId", value: userId)//用户UserId
            mysoap.addParam("path", value: path)//头像图片的路径

            mysoap.send({ (data) in
            if data["result"] != nil{
                if(data["result"].string == "true"){
                    successCallback(msg: data["msg"].string!)
                }else{
                    failCallback(error: data["msg"].string!)
                }
            }else{
                failCallback(error: "上传失败")
            }
        }) { (error) in
            failCallback(error: "上传失败")
        }
    }
    
    //函数名:UpdatePassword  4-修改密码
    //@param  userName  String  用户名
    //@param  oldpwd  String  原密码
    //@param  newpwd  String  新的密码
    //成功返回true或者false
    static func UpdatePassword(userName:String,
                             oldpwd:String,
                             newpwd:String,
                             successCallback:(msg:String)->Void,
                             failCallback:(error:String)->Void)
    {
            let mysoap=soapUtil()

            mysoap.setName(ASMX_NAME, methodName: "UpdatePassword")

            mysoap.addParam("userName", value: userName)//用户名
            mysoap.addParam("oldpwd", value: oldpwd)//原密码
            mysoap.addParam("newpwd", value: newpwd)//新的密码

            mysoap.send({ (data) in
                if data["result"] != nil{
                    if(data["result"].string == "true"){
                        successCallback(msg: data["msg"].string!)
                    }else{
                        failCallback(error: data["msg"].string!)
                    }
                }else{
                    failCallback(error: "修改失败")
                }
        }) { (error) in
            failCallback(error: "修改失败")
        }
    }

}
